﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoUpdate.Comm
{
    public class CommHelper
    {
        /// <summary>
        /// Bytes到KB,MB,GB,TB单位智能转换
        /// </summary>
        /// <param name="len">文件大小</param>
        /// <returns></returns>
        public static string ConverBytes(long len)
        {
            double leng = Convert.ToDouble(len);
            string[] size = {"Bytes", "KB", "MB", "GB", "TB"};
            int order = 0;
            while (leng >= 1024 && order + 1 < size.Length)
            {
                order++;
                leng /= 1024;
            }
            return String.Format("{0:0.##} {1}",leng,size[order]);
        }
    }
}
